#include "tcp_socket.h"



TcpSocket::TcpSocket(QObject* parent) : QTcpSocket(parent)
{
    connect(this,SIGNAL(readyRead()),this,SLOT(slot_data_received()));
    connect(this,SIGNAL(disconnected()),this,SLOT(slot_disconnected()));
}

TcpSocket::~TcpSocket()
{

}



void TcpSocket::slot_data_received()
{
    while(bytesAvailable() > 0)
    {
        char buf[1024];
        int length = bytesAvailable();

        read(buf,length);

        QString msg = buf;

        emit signal_receive_data(msg,length,this->socketDescriptor());
        emit signal_receive_data(msg.toLatin1(),this->socketDescriptor());
    }
}

void TcpSocket::slot_disconnected()
{
    emit signal_disconnected(this->socketDescriptor());
}
